<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>充值管理</title>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/default/easyui.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/themes/icon.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/plugins/jQuery/demo.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/admin/css/form.css"/>
	
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.min.js"></script>
	<script src="${pageContext.request.contextPath }/plugins/jQuery/jquery.easyui.min.js"></script>
	<script src="${pageContext.request.contextPath}/plugins/jQuery/easyui-lang-zh_CN.js"></script>
	<script src="${pageContext.request.contextPath}/admin/js/reg.js"></script>
	<style type="text/css">
		li{line-height:22px; vertical-align:middle;}
		.h35{height:30px; line-height:30px; vertical-align:middle;}
	</style>
	<script>
		$(function(){
			$('#return_kind').combobox({
				valueField:'value',
				textField:'text',
				data:[{"value":"00","text":"残次退赔"},
					{"value":"01","text":"整件退赔"},
					{"value":"02","text":"二次转卖"}
				],
				onLoadSuccess : function(data) {
		            $('#return_kind').combobox("setValue","00");
	        	}
			});


			$('#question_kind').combobox({
				valueField:'value',
				textField:'text',
				data:[{"value":"00","text":"少斤两"},
					{"value":"01","text":"腐烂"}
				],
				onLoadSuccess : function(data) {
		            $('#question_kind').combobox("setValue","00");
	        	}
			});
			
			var msg="${addMsg}";
			if(msg!=null && msg!=""){
				$.messager.alert('系统消息',msg);
			}			
		});
	</script>
  </head>
  <body>
  	<form action="${pageContext.request.contextPath }/admin/return/addreturnbill" method="post" name="returnForm" id="returnForm">
	<div>
		<div class="h35" style="float:left; width:100px; text-align:right;">客户姓名:</div>
		<div class="h35" style="float:left; width:180px; color:green; padding-left:20px;">${customer.cust_name }</div>
		<div class="h35" style="float:left; width:100px; text-align:right;">手机号:</div>
		<div class="h35" style="float:left; width:180px; color:green; padding-left:20px;">${customer.mobile }</div>
		<div class="h35" style="float:left; width:100px; text-align:right;">退赔订单日期:</div>
		<div class="h35" style="float:left; width:180px; color:green; padding-left:20px;"><input id="return_time" name="return_time" class="easyui-datebox"  style="width:120px" value="${order_date }"></div>
		<div style="clear:left;"></div>
		
		<div class="h35" style="float:left; width:100px; text-align:right;">所属服务站:</div>
		<div class="h35" style="float:left; width:180px; color:green; padding-left:20px;">${customer.station_name }</div>
		<div class="h35" style="float:left; width:100px; text-align:right;">当前账号余额:</div>
		<div class="h35" style="float:left; width:180px; color:green; padding-left:20px;">￥${customer.amount }</div>
		<div class="h35" style="float:left; width:100px; text-align:right;">&nbsp;</div>
		<div class="h35" style="float:left; width:180px; color:green; padding-left:20px;">
			<a href="#" class="easyui-linkbutton" id="add" iconCls="icon-search" onclick="findGoodsList()" style="width:80px;">查询</a>
		</div>
		
		<div style="clear:left;"></div>
	</div>
	<div style="border-top:1px dashed gray; height:18px;"></div>
	<input type="hidden" name="order_date" id="order_date" value="${order_date }"/>
	<input type="hidden" name="cust_id" value="${customer.cust_id }"/>
	<input type="hidden" name="acct_id" value="${customer.acct_id }"/>
	<div>
		<div style="float:left; width:210px; height:183px; padding-left:36px;">
			<select size="11" style="width:200px; border:1px solid #bbbbbb; padding:6px;" id="goodsinfo">
				${goodsList }
			</select>
		</div>
		<div style="float:left; width:70px; height:183px;  padding:6px; line-height:180px; vertical-align:middle;text-align:center;">
			<a href="javascript:addItem()" class="easyui-linkbutton" style="width:60px;height:22px;"> &nbsp;&nbsp;》》</a>&nbsp;&nbsp;
		</div>
		<div style="float:left; width:780px; height:183px; border:1px solid #bbbbbb;  padding:6px;" id="itemsDiv">
			<div class="topHead">
				<div style="float:left; width:180px; text-align:center;" class="h35">SKU名称</div>
				<div style="float:left; width:100px; text-align:center;" class="h35">当前售价</div>
				<div style="float:left; width:100px; text-align:center;" class="h35">退赔类型</div>
				<div style="float:left; width:100px; text-align:center;" class="h35">退赔件数</div>
				<div style="float:left; width:100px; text-align:center;" class="h35">退赔金额</div>
				<div style="float:left; width:100px; text-align:center;" class="h35">问题类型</div>
				<div style="float:left; width:100px; text-align:center;" class="h35">操作</div>
				<div style="clear:left;"></div>
			</div>		

		</div>
		<div style="clear:left; height:30px;"></div>
	</div>
	<div style="border-top:1px dashed gray; height:18px;"></div>
	
	<div>
		<div class="h35" style="float:left; width:100px; text-align:right;">退赔金额:<input type="hidden" id="amounts" name="amounts" value="0"/></div>
		<div class="h35" style="float:left; width:180px; color:red; padding-left:20px; font-size:16px; font-weight:bold;" id="r_amount">￥ 0.00 元</div>
		<div class="h35" style="float:left; width:100px; text-align:right;">退赔密码:</div>
		<div class="h35" style="float:left; width:180px; color:green; padding-left:20px;"><input type="password" name="password" id="password" prompt="请输入退赔密码"/></div>	
		<div style="clear:left;"></div>
	</div>
	<div class="fitem h35" style="padding-left:47px;">
		<label>图片上传:</label>
		<input type="file" name="image" id="imageFile">
		<button id="upload" onclick="return false;">上传图片</button>
		<a href="javascript:clearImgs()" class="easyui-linkbutton" data-options="iconCls:'icon-my-clear'" style="width:100px;margin:0px 3px;">清空图片</a> 	
		<!-- 存储图片地址，并显示图片 -->
		<input type="hidden" name="rootPath" id="rootPath" value="${pageContext.request.contextPath }">
		<input type="hidden" name="pictureSrc" id="pictureSrc">
	</div>
	<div class="fitem" id="show" style="padding-left:47px;"></div>
	<div style="padding-left:47px; margin-top:9px;">
		退赔原因：<textarea name="reason" cols="120" rows="6" style="align:top;"></textarea>
	</div>
	<div class="h35" style="width:1142px; text-align:center;">
		<a href="#" class="easyui-linkbutton" id="add" iconCls="icon-add" onclick="checkForm()" style="width:80px;">退赔</a>
		<a href="#" class="easyui-linkbutton" id="add" iconCls="icon-undo" onclick="javascript:history.go(-1)" style="width:80px;">取消</a>
	</div>
	</form>
	<script>
		function addItem(){
			var goodsText=$('#goodsinfo option:selected').text();//选中的文本
			var goodsValue=$('#goodsinfo option:selected').val();//选中的值
			var custid='${customer.cust_id}';
			if(goodsValue==null){
				$.messager.alert('系统消息','<span style=\"color:red;\">您还没有选中任何菜品！<br/>请先从左边选择框中选择SKU名称！</span>');
				return;
			}
			var obj = $("input[name='goods_ids']");
			if(obj!=null){
				for (var i = 0; i < obj.length; i++) {
					var val=obj.eq(i).val();
					if(goodsValue==val){
						$.messager.alert('系统消息','<span style=\"color:red;\">您选择的SKU名称已经添加到退赔列表！<br/>请直接修改信息！</span>');
						return;
					}
				}
			}
			$.post("${pageContext.request.contextPath}/admin/return/findGoodsPrice",{order_date:$('#return_time').combobox("getValue"),custid:custid,goodsid:goodsValue},
						function(data){
							if(data==""){
								$.messager.alert('系统消息','<span style=\"color:red;\">没有找到该商品的价格信息！</span>');
								$('#dlg').dialog('close');	 
							}else{
						//		var goods_price='￥200.00';
								var item='<div class="cnt" id="itemDiv" style="border-top:1px dashed #bbbbbb;">';
								item=item+'<div style="float:left; width:180px; text-align:center;" class="h35">'+goodsText+'<input type="hidden" name="goods_ids" value="'+goodsValue+'"></div>';
								item=item+'<div style="float:left; width:100px; text-align:center;" class="h35">'+data+'<input type="hidden" name="goods_prices" value="'+data+'"></div>';
								item=item+'<div style="float:left; width:100px; text-align:center;" class="h35"><select style="width:88px;" name="returnKind">';
								item=item+'${returnKind}</select></div>';
								item=item+'<div style="float:left; width:100px; text-align:center;" class="h35"><input name="nums" style="width:50px; text-align:center;" value="0"></div>';
								item=item+'<div style="float:left; width:100px; text-align:center;" class="h35"><input name="amount" style="width:50px; text-align:center;" value="0" onchange="calc()"></div>';
								item=item+'<div style="float:left; width:100px; text-align:center;" class="h35"><select style="width:88px;" name="questionKind">';
								item=item+'${questionKind}</select></div>';
								item=item+'<div style="float:left; width:100px; text-align:center;" class="h35"><img src="${pageContext.request.contextPath}/plugins/jQuery/themes/icons/minus.png" onclick="delReturnItem(this)" border="0"  style="cursor:pointer;"/></div>';
								item=item+'<div style="clear:left;"></div>';
								item=item+'</div>';
								$("#itemsDiv").append(item);	
							}	
						},"text");
			
			
		}
		
		// 查询指定日期的订单商品列表 	findGoodsList
		function findGoodsList(){
			var custid='${customer.cust_id}';
			var o_date=$('#return_time').combobox("getValue");
			$.post("${pageContext.request.contextPath}/admin/return/findGoodsList",{order_date:o_date,custid:custid},
				function(data){
					document.getElementById("goodsinfo").options.length = 0;
					if(data==""){
						$.messager.alert('系统消息','<span style=\"color:red;\">'+o_date+'没有订购商品！</span>');
					}else{
						$("#goodsinfo").append(data);
						$("div").remove("#itemDiv");
						$("#order_date").val(o_date);
					}
					
				},"text");
		}
		
		// 清除已经上传的图片，重新上传
       	function clearImgs(){
			$("#show").html("");
			$("#pictureSrc").val("");
		}


		function delReturnItem(comp){
			$(comp).parent().parent().remove();
		}

		function calc(){
			var amounts = $("input[name='amount']");
			var totals=0;
			if(amounts!=null){
				for (var i = 0; i < amounts.length; i++) {
					var val=amounts.eq(i).val();
					totals=totals+parseFloat(val);
				}
			}
			$('#r_amount').html('￥ '+totals+' 元');
			$('#amounts').val(totals);
		}

		function checkForm(){
			// 判断日期框的值
			var r_time = $('#return_time').datebox('getValue');
			if(r_time==null || r_time==''){
				$.messager.alert('系统消息','<span style=\"color:red;\">请选择退赔日期！</span>');
				return;
			}
			
			// 判断是否存在退赔商品
			var obj = $("input[name='goods_ids']");
			if(obj==null || obj.length==0){
				$.messager.alert('系统消息','<span style=\"color:red;\">没有作任何退赔处理，无法提交！</span>');
				return;
			}
			
			// 判断退赔件数输入是否正确
			var objNum = $("input[name='nums']");
			if(objNum!=null && objNum.length>0){
				for(var i=0;i<objNum.length;i++){
					if(!isSignInteger(objNum[i].value)){
						$.messager.alert('系统消息','<span style=\"color:red;\">退赔件数不能为零，且必须为数字！</span>');
						return;
					}
				}		
			}
			
			// 判断退赔金额输入是否正确
			var objAmount = $("input[name='amount']");
			if(objAmount!=null && objAmount.length>0){
				for(var i=0;i<objAmount.length;i++){
					if(isZero(objAmount[i].value) || !isSignDecimal(objAmount[i].value)){
						$.messager.alert('系统消息','<span style=\"color:red;\">退赔金额不能为零，且必须为数字！</span>');
						return;
					}
				}		
			}

			// 判断是否输入退赔密码
			var pass=$('#password').val();
			if(pass==null || $.trim(pass)==''){
				$.messager.alert('系统消息','<span style=\"color:red;\">请输入退赔密码！</span>');
				return;
			}
			$("#returnForm").submit();
		}


	</script>
  	<script type="text/javascript" src="${pageContext.request.contextPath }/plugins/upload/ajaxfileupload.js"></script>
	<script type="text/javascript" src="${pageContext.request.contextPath }/plugins/upload/upload.js"></script>  
  </body>
</html>
